package com.cn.wanxi.servlet.message;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.MessageModel;
import com.cn.wanxi.service.IMessageService;
import com.cn.wanxi.service.impl.MessageServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/message/messageUpdate")
public class MessageUpdateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //2.接收前台传数据过来
        String id=req.getParameter("id");
        System.out.println(id);
        int messageid = id == null ? 0 : Integer.parseInt(id);
        String name=req.getParameter("name");
        String phone=req.getParameter("phone");
        String mailbox=req.getParameter("mailbox");
        String project=req.getParameter("project");
        String date=req.getParameter("date");
        String message=req.getParameter("message");
        String feedback=req.getParameter("feedback");

        //3.封装到实体类UserModel
        MessageModel messageModel=new MessageModel();
        messageModel.setId(messageid);
        messageModel.setName(name);
        messageModel.setPhone(phone);
        messageModel.setMailbox(mailbox);
        messageModel.setProject(project);
        messageModel.setDate(date);
        messageModel.setMessage(message);
        messageModel.setFeedback(feedback);

        //4.服务逻辑层
        IMessageService iMessageService=new MessageServiceImpl();
        //5.调用得到页面所需要的数据

        int count=iMessageService.findUpdate(messageModel);

        //7.将数据转发到页面
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
